import { ActionTypes } from '../constants'
const initialState = {
    isLogin: false,
    user: {}
}

export default function user(state = initialState, { type, payload }) {
    switch (type) {
        case ActionTypes.API_LOGIN_SUCCESS:
            return {
                ...state,
                isLogin: true,
                user: payload.user
            }
        case ActionTypes.API_UPDATE_USER_INFO:
        const { name, gender } = payload
        const { user } = state;
        console.log('API_UPDATE_USER_INFO', name, gender, user, state)
        return {
            ...state,
            user: {
                ...user,
                name: name,
                gender: gender
            }
        }
    }
    return state
}